// 定义压缩文件类型
const productionGzipExtensions = ['js', 'css']
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const path = require('path')
const TransformPages = require('uni-read-pages')
const { webpack } = new TransformPages()

// 开发环境
const ifProduct = process.env.NODE_ENV !== 'development'
const ifH5 = process.env.UNI_PLATFORM === 'h5'
const plugins = [];
// gzip打包

plugins.push(
	new webpack.DefinePlugin({
		ROUTES: webpack.DefinePlugin.runtimeValue(() => {
			const tfPages = new TransformPages({
				includes: ['path', 'name', 'aliasPath']
			});
			return JSON.stringify(tfPages.routes)
		}, true )
	})
)


module.exports = {
	productionSourceMap: false, // 生产打包时不输出map文件，增加打包速度
	transpileDependencies: ['uview-ui'],
	configureWebpack: config => {
		if (process.env.NODE_ENV === 'production') {
			config.optimization.minimizer[0].options.terserOptions.compress.warnings = false
			config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
			config.optimization.minimizer[0].options.terserOptions.compress.drop_debugger = true
			config.optimization.minimizer[0].options.terserOptions.compress.pure_funcs = ['console.log']
		}
		config.plugins = config.plugins.concat(plugins)
	}
}
